unit UFrmConsultaCor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFrmConsultaPai, StdCtrls, Grids, DBGrids,UCor,UCtrlCor,Udm,UFrmCadastroCor;

type
  TFrmConsultaCor = class(TFrmConsultaPai)
    procedure btnNovoClick(Sender: TObject);
    procedure edtBuscarChange(Sender: TObject);
    procedure btnAlterarClick(Sender: TObject);
    procedure dbgConsultaDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);

  private
    { Private declarations }
    umaCor: Cor;
    umFrmCadastroCor : TFrmCadastroCor;
    umaCtrlCor : CtrlCor;
    umDM : TDM;

  public
    { Public declarations }
      procedure ConhecaObj(aCor:Cor);
  end;

var
  FrmConsultaCor: TFrmConsultaCor;

implementation
Uses
  Uaplicacao;


{$R *.dfm}

{ TFrmConsultaCor }

procedure TFrmConsultaCor.btnAlterarClick(Sender: TObject);
begin
  inherited;
  umaCor.setId(0);
  umaCtrlCor.Carrega(umaCor);
  umFrmCadastroCor.conhecaObj(umaCor,umaCtrlCor);
  umFrmCadastroCor.edtNome.Enabled := True;
  umFrmCadastroCor.carregaObjFrm;
  umFrmCadastroCor.ShowModal;
end;

procedure TFrmConsultaCor.btnNovoClick(Sender: TObject);
begin
  inherited;
  umFrmCadastroCor.conhecaObj(umaCor, umaCtrlCor);
  umFrmCadastroCor.limpaCampos;
  umFrmCadastroCor.desativaCampos;
  umFrmCadastroCor.ativaCampos;
  umFrmCadastroCor.ShowModal;
end;

procedure TFrmConsultaCor.ConhecaObj(aCor: Cor);
var
 valor : Integer; // Valor relacionado ao nivel de acesso de cada usuario
begin
  umaCor:= aCor;
  umaCtrlCor := CtrlCor.Create;
  umFrmCadastroCor:=TFrmCadastroCor.Create(nil);
  self.dbgConsulta.DataSource := umaCtrlCor.GetDS;
  umaCtrlCor.buscar('');
end;

procedure TFrmConsultaCor.dbgConsultaDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  inherited;

  with dbgConsulta do
   begin
     if Column.FieldName = 'DATACADASTRO' then  // Coluna a ser Pintada
      begin
        //Canvas.Brush.Color := clSilver; // Cor de Fundo
        if Column.Field.AsDateTime <= Now then
         begin
           Canvas.Brush.Color:= clYellow;  // Cor de Fundo
           //Canvas.Font.Color := clRed;    // Cor do texto
         end
        else
         Canvas.Brush.Color:= clRed;  // Cor de Fundo
           //Canvas.Font.Color := clRed;    // Cor do texto
      end;
     Canvas.FillRect(Rect);
     DefaultDrawColumnCell(Rect,DataCol,Column,State);
   end;

end;

procedure TFrmConsultaCor.edtBuscarChange(Sender: TObject);
begin
  inherited;
  umaCtrlCor.Buscar(self.edtBuscar.Text)
end;


end.

